package com.wx.mythread.threadmethod;

/**
 * wait只释放当前的那把锁
 */
public class StudyWaitNotifyRelease {

    private static volatile Object resourcesA = new Object();
    private static volatile Object resourcesB = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (resourcesA) {
                    System.out.println(Thread.currentThread().getName() + "拿到了 锁 resourcesA");
                    synchronized (resourcesB) {
                        System.out.println(Thread.currentThread().getName() + "拿到了 锁 resourcesB");

                        System.out.println(Thread.currentThread().getName() + "调用wait释放resourcesA锁");
                        try {
                            resourcesA.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (resourcesA) {
                    System.out.println(Thread.currentThread().getName() + "获取到了resourcesA锁");
                    synchronized (resourcesB) {
                        System.out.println(Thread.currentThread().getName() + "获取到了resourcesB锁");
                    }
                }
            }
        });

        thread1.start();
        Thread.sleep(1000);
        thread2.start();


    }


}
